﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_EXPERIENCE。
    /// </summary>
    public class ALARM_EXPERIENCE
    {
        public ALARM_EXPERIENCE()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ALARMEXPERID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_EXPERIENCE");
            strSql.Append(" where ALARMEXPERID=:ALARMEXPERID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMEXPERID", OracleType.VarChar,50)};
            parameters[0].Value = ALARMEXPERID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FiberRMS.Model.AlarmManager.ALARM_EXPERIENCE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_EXPERIENCE(");
            strSql.Append("ALARMEXPERID,EQUIPMODEL,DESCRIPTION,ANALYSIS,DISPOSEMETHOD,VENDOR,REMARK,ALARMNUMBER,REPAIRMAN)");
            strSql.Append(" values (");
            strSql.Append(":ALARMEXPERID,:EQUIPMODEL,:DESCRIPTION,:ANALYSIS,:DISPOSEMETHOD,:VENDOR,:REMARK,:ALARMNUMBER,:REPAIRMAN)");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMEXPERID", OracleType.VarChar,10),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,20),
					new OracleParameter(":DESCRIPTION", OracleType.VarChar,500),
					new OracleParameter(":ANALYSIS", OracleType.VarChar,500),
					new OracleParameter(":DISPOSEMETHOD", OracleType.VarChar,500),
					new OracleParameter(":VENDOR", OracleType.VarChar,200),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50),
                   new OracleParameter(":REPAIRMAN", OracleType.VarChar,64)};
            parameters[0].Value = model.ALARMEXPERID;
            parameters[1].Value = model.EQUIPMODEL;
            parameters[2].Value = model.DESCRIPTION;
            parameters[3].Value = model.ANALYSIS;
            parameters[4].Value = model.DISPOSEMETHOD;
            parameters[5].Value = model.VENDOR;
            parameters[6].Value = model.REMARK;
            parameters[7].Value = model.ALARMNUMBER;
            parameters[8].Value = model.REPAIRMAN;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(FiberRMS.Model.AlarmManager.ALARM_EXPERIENCE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_EXPERIENCE set ");
            strSql.Append("EQUIPMODEL=:EQUIPMODEL,");
            strSql.Append("DESCRIPTION=:DESCRIPTION,");
            strSql.Append("ANALYSIS=:ANALYSIS,");
            strSql.Append("DISPOSEMETHOD=:DISPOSEMETHOD,");
            strSql.Append("VENDOR=:VENDOR,");
            strSql.Append("REMARK=:REMARK,");
            strSql.Append("ALARMNUMBER=:ALARMNUMBER,");
            strSql.Append("REPAIRMAN=:REPAIRMAN");
            strSql.Append(" where ALARMEXPERID=:ALARMEXPERID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMEXPERID", OracleType.VarChar,10),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,20),
					new OracleParameter(":DESCRIPTION", OracleType.VarChar,500),
					new OracleParameter(":ANALYSIS", OracleType.VarChar,500),
					new OracleParameter(":DISPOSEMETHOD", OracleType.VarChar,500),
					new OracleParameter(":VENDOR", OracleType.VarChar,200),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50),
                   	new OracleParameter(":REPAIRMAN", OracleType.VarChar,64)};
            parameters[0].Value = model.ALARMEXPERID;
            parameters[1].Value = model.EQUIPMODEL;
            parameters[2].Value = model.DESCRIPTION;
            parameters[3].Value = model.ANALYSIS;
            parameters[4].Value = model.DISPOSEMETHOD;
            parameters[5].Value = model.VENDOR;
            parameters[6].Value = model.REMARK;
            parameters[7].Value = model.ALARMNUMBER;
            parameters[8].Value = model.REPAIRMAN;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string ALARMEXPERID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_EXPERIENCE ");
            strSql.Append(" where ALARMEXPERID=:ALARMEXPERID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMEXPERID", OracleType.VarChar,50)};
            parameters[0].Value = ALARMEXPERID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_EXPERIENCE GetModel(string ALARMEXPERID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMEXPERID,EQUIPMODEL,DESCRIPTION,ANALYSIS,DISPOSEMETHOD,VENDOR,REMARK,ALARMNUMBER,REPAIRMAN from ALARM_EXPERIENCE ");
            strSql.Append(" where ALARMEXPERID=:ALARMEXPERID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMEXPERID", OracleType.VarChar,50)};
            parameters[0].Value = ALARMEXPERID;

            FiberRMS.Model.AlarmManager.ALARM_EXPERIENCE model = new FiberRMS.Model.AlarmManager.ALARM_EXPERIENCE();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ALARMEXPERID = ds.Tables[0].Rows[0]["ALARMEXPERID"].ToString();
                model.EQUIPMODEL = ds.Tables[0].Rows[0]["EQUIPMODEL"].ToString();
                model.DESCRIPTION = ds.Tables[0].Rows[0]["DESCRIPTION"].ToString();
                model.ANALYSIS = ds.Tables[0].Rows[0]["ANALYSIS"].ToString();
                model.DISPOSEMETHOD = ds.Tables[0].Rows[0]["DISPOSEMETHOD"].ToString();
                model.VENDOR = ds.Tables[0].Rows[0]["VENDOR"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                model.ALARMNUMBER = ds.Tables[0].Rows[0]["ALARMNUMBER"].ToString();
                model.REPAIRMAN = ds.Tables[0].Rows[0]["REPAIRMAN"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct a.ALARMEXPERID,m.resourcename as EQUIPMODEL,m.alarmcause as DESCRIPTION,a.ANALYSIS,a.DISPOSEMETHOD,a.VENDOR,a.REMARK,a.ALARMNUMBER,a.REPAIRMAN ");
                                                   
            strSql.Append(" from ALARM_EXPERIENCE a,alarm_map m ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where (m.resourceid=a.EQUIPMODEL and m.alarmmapid=a.DESCRIPTION) and " + strWhere);
            }
            else
            {
                strSql.Append(" where m.resourceid=a.EQUIPMODEL and m.alarmmapid=a.DESCRIPTION ");
            }
            return OracleHelper.Query(strSql.ToString());
        }

        public DataSet getSame(string id)
        {
            string where = "";
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct a.ALARMEXPERID,m.resourcename as EQUIPMODEL,m.alarmcause as DESCRIPTION,a.ANALYSIS,a.DISPOSEMETHOD,a.VENDOR,a.REMARK,a.ALARMNUMBER ");
            strSql.Append(" from ALARM_EXPERIENCE a,alarm_map m ");
            if (id != "" && id != null)
            {
                string[] arr = id.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (i != arr.Length - 1)
                    {
                        where += "'" + arr[i] + "',";
                    }
                    else
                    {
                        where += "'" + arr[i] + "'";
                    }


                }
                strSql.Append(" where (m.resourceid=a.EQUIPMODEL and m.alarmmapid=a.DESCRIPTION) and a.ALARMEXPERID in (" + where + ") ");
            }
            else
            {

                strSql.Append(" where 1=2 ");
            }
            return OracleHelper.Query(strSql.ToString());

        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_EXPERIENCE";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

